package com.synchrona.updateSyncManager;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.synchrona.account.Account;
import com.synchrona.common.Common;
import com.synchrona.user.User;

public class UpdateProcessor {
	
	
	//Returns the user object
	public static User getProcessedUser(ResultSet rs) {
		User user = new User();
		
		try{
			while (rs.next()) {
				int id = rs.getInt(Common.colMasterId);
				String stat = rs.getString(Common.colMasterStatus);
				String email = rs.getString(Common.colUserEmail);
				System.out.println(id + " " + stat +" " + email + " ");
				
				user.setUserId(rs.getInt(Common.colMasterId));;
				user.setStatus(rs.getString(Common.colMasterStatus));
				user.setEmail(rs.getString(Common.colUserEmail));
				user.setUserName(rs.getString(Common.colMasterUserName));
				user.setRegisteredDate(rs.getDate(Common.colUserRegDate));
				
			}
			rs.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
		return user;
		
	}
	
	//Returns the processed account list
	public static List<Account> getProcessedAccounts(ResultSet resultSet){
		List<Account> accountList = new ArrayList<Account>();
		try {
			while (resultSet.next()) {
				Account account = new Account();
				account.setAccountId(resultSet.getString(Common.colAccountId));
				account.setAccountEmail(resultSet.getString(Common.colAccountEmail));
				account.setServiceUserName(resultSet.getString(Common.colAccountUserName));
				account.setServicePassword(resultSet.getString(Common.colAccountPassword));
				account.setServiceId(resultSet.getString(Common.colAccountServiceId));
				
				accountList.add(account);
				System.out.println(account.getAccountId() + " " + account.getServiceUserName() 
						+ " " + account.getServicePassword()  + " ");
			}
			resultSet.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return accountList;
	}
	
}
